package com.xgure.utils;

import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 线程变量
 *
 */
public class BaseContextUtil {

    private static final ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal<>();

    private static final String SHOP_ID = "shopId";
    private static final String USER_ID = "userId";

    /**
     * 登录时设置店铺ID
     *
     */
    public static void setCurrentShopId(Long shopId) {
        threadLocal.set(Map.of(SHOP_ID, shopId));
    }

    /**
     * 获取店铺ID
     *
     */
    public static Long getCurrentShopId() {
        return (Long) threadLocal.get().get(SHOP_ID);
    }

    /**
     * 登录时设置用户ID
     *
     */
    public static void setCurrentUserId(Long userId) {
        threadLocal.set(Map.of(USER_ID, userId));
    }

    /**
     * 获取用户ID
     *
     */
    public static Long getCurrentUserId() {
        return (Long) threadLocal.get().get(USER_ID);
    }

}
